package com.oig.sys.auth.dao;

import com.oig.sys.auth.entity.TbResourceDataCfg;
import com.oig.sys.auth.vo.ResourceDataCfgVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbResourceDataCfgDao extends JpaRepository<TbResourceDataCfg, Integer> {

	TbResourceDataCfg getTbResourceDataCfgById(Integer id);


	@Query("select new com.oig.sys.auth.vo.ResourceDataCfgVo(t.id,t.resourceId,t.userRelationType,t.userRelationId," +
			" t.dataEqType, t.dataEqFiled, t.dataEqSql, t.whitelist, t.excludeFiled, t.status, t.tenantId, t.tenantCode, t.tenantName," +
			" t.createUserName, t.createTime, t.lastUpdateName, t.lastUpdateTime) " +
			" from TbResourceDataCfg t where t.resourceId=:resourceId ")
	List<ResourceDataCfgVo> findAllResourceDataCfg(@Param("resourceId") Integer resourceId);


//	@Query("select new com.oig.sys.auth.vo.ResourceDataCfgVo(t.id,t.resourceId,t.userRelationType,t.userRelationId," +
//			" t.dataEqType, t.dataEqFiled, t.dataEqSql, t.whitelist, t.excludeFiled, t.status, t.tenantId, t.tenantCode, t.tenantName," +
//			" t.createUserName, t.createTime, t.lastUpdateName, t.lastUpdateTime) " +
//			" from TbResourceDataCfg t where t.resourceId=:resourceId and t.tenantId in(:tenantIdList)")
//	List<ResourceDataCfgVo> findAllResourceDataCfg(@Param("resourceId") Integer resourceId, @Param("tenantIdList") List<Object> tenantIdList);

	@Query("select new com.oig.sys.auth.vo.ResourceDataCfgVo(t.id,t.resourceId,t.userRelationType,t.userRelationId," +
			" t.dataEqType, t.dataEqFiled, t.dataEqSql, t.whitelist, t.excludeFiled) " +
			" from TbResourceDataCfg t where t.resourceId=:resourceId and t.tenantId=:tenantId")
	List<ResourceDataCfgVo> findUseResourceDataCfg(@Param("resourceId") Integer resourceId, @Param("tenantId") Integer tenantId);

	@Query("select new com.oig.sys.auth.vo.ResourceDataCfgVo(t.id,t.resourceId,t.userRelationType,t.userRelationId," +
			" t.dataEqType, t.dataEqFiled, t.dataEqSql, t.whitelist, t.excludeFiled) " +
			" from TbResourceDataCfg t where t.resourceId=:resourceId and t.tenantId=:tenantId and t.status=:status")
	List<ResourceDataCfgVo> findUseResourceDataCfg(@Param("resourceId") Integer resourceId, @Param("tenantId") Integer tenantId, @Param("status") String status);

}
